package com.longrise.android.by.javascriptInterface;

import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.ShareParams;
import com.longrise.android.by.activity.BYWebActivity;

/**
 * Created by godliness on 2017/4/25.
 */

public class PlanConInterface {

    private BYWebActivity mCxt;

    public PlanConInterface(BYWebActivity act) {
        this.mCxt = act;
    }

    @JavascriptInterface
    public void shareParams(String title, String content, String url, String iconUrl) {
        if (mCxt != null) {
            ShareParams shareParams = new ShareParams();
            shareParams.mTitle = title;
            shareParams.mContent = content;
            shareParams.mUrl = url;
            shareParams.mHeadUrl = iconUrl;
            mCxt.showShareDialog(shareParams);
        }
    }

    @JavascriptInterface
    public void copyMail(final String mail) {
        if (!TextUtils.isEmpty(mail) && mCxt != null) {
            mCxt.mHandler.post(new Runnable() {
                @Override
                public void run() {
                    ClipboardManager cmb = (ClipboardManager) mCxt.getSystemService(Context.CLIPBOARD_SERVICE);
                    cmb.setText(mail);
                    mCxt.showToast(mCxt.getString(R.string.toast_copy_success));
                }
            });
        }
    }

    @JavascriptInterface
    public void loadFinish() {
        mCxt.mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCxt.isLoading(false);
            }
        });
    }
}
